package com.ruoyi.common.utils.poi.word.render;

import cn.hutool.core.io.FileUtil;
import com.aspose.words.DocumentBuilder;
import lombok.Data;
import java.io.FileInputStream;

@Data
public class PoiDataImg extends PoiDataAfterCreateWord {
    /**
     * 书签
     */
    protected String bookmark;
    /**
     * html 内容、图片本地路径
     */
    protected String value;

    /**
     * 宽
     */
    private int width;
    /**
     * 高
     */
    private int height;

    public PoiDataImg() {
    }

    public PoiDataImg(String bookmark, String value, int width, int height) {
        this.width = width;
        this.height = height;
        this.bookmark = bookmark;
        this.value = value;
    }

    @Override
    public void handle(DocumentBuilder builder) throws Exception {
        super.handle(builder);
        builder.moveToBookmark(bookmark);
        if (FileUtil.exist(value)) {
            FileInputStream in = new FileInputStream(value);
            builder.insertImage(in, width, height);
            in.close();
        }
    }
}
